<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>RequestBody传递JSON类型参数</title>
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script src="./js/bootstrap.js"></script>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<body>
<button onclick="sendAjax();" class="btn-success">发送JSON数据到后端</button>
<script>
    function sendAjax(){
        let user = {id:1, name:"小高",age:44,birthday:"2022-05-03 10:30:00",salary:11.2483};
        let userDate = JSON.stringify(user);
        // 使用ajax 发送json数据到后端控制住器
        $.ajax({
            url:"http://localhost:8080${pageContext.request.contextPath}/ajax/test1",
            type:"post",
            contentType:"application/json",
            data:userDate, // 发送的json类型参数
            success:function (res){ // 请求成功后的回调函数
                // console.log
                console.log(res)
            }
        });
    }
</script>
</body>
</html>
